// formPackage/components/newsItem/newsItem.js

const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    productReply: {
      type: Object,
      value: {}
    },
    isDetail: {
      type: Boolean,
      value: false,
    }
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      // console.log("JJLog:之类来==：" + this.properties.show)
      // this.setData({
      //   showPop: this.properties.show
      // })
      if (this.properties.productReply.score) {
        let arr = [];
        for (let i = 0; i < this.properties.productReply.score; i++) {
          arr.push(1);
        }
        let len = arr.length;
        if (len < 5) {
          for (let i = len; i < 5; i++) {
            arr.push(0);
          }
        }
        this.setData({
          starArr: arr
        })
      }

    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    starArr: []
  },

  /**
   * 组件的方法列表
   */
  methods: {
    previewImgs(e) {
      let url = e.currentTarget.dataset.url;
      let urls = e.currentTarget.dataset.imgs;
      wx.previewImage({
        current: url,
        urls: urls,
      })
    },

    //预览图片或者视频:
    // previewImgs(e) {
    //   let index = e.currentTarget.dataset.index;
    //   let images = this.properties.newsItem.images;
    //   let item = images[index];
    //   if (item.fileType == 2) {
    //     //如果是视频:
    //     app.globalData.videoUrl = item.url;
    //     wx.navigateTo({
    //       url: '/pages/videoPlay/videoPlay',
    //     })
    //     return;
    //   }
    //   let urls = [];
    //   images.forEach((i) => {
    //     if (i.fileType == 1) {
    //       urls.push(i.url)
    //     } else {
    //       urls.push(i.url + this.data.videoJoint);
    //     }
    //   })
    //   wx.previewImage({
    //     current: item.url,
    //     urls: urls,
    //   })
    // },


    copyWxChatAction(e) {
      let text = e.currentTarget.dataset.text;
      wx.setClipboardData({
        data: text,
        success: function (res) {
          wx.getClipboardData({
            success: function (res) {
              wx.showToast({
                title: '复制微信号成功'
              })
            },
            fail: function (err) {
              wx.showToast({
                title: '复制失败',
                icon: "none"
              })
            }
          })
        }
      })
    },

  },

})
